

var ValidationRules = ValidationRules || {};


ValidationRules.addRules = function () {


    $.each(ValidationRules.Rules, function (index, value) {
        if ($(value.elementName).length > 0) {
            ValidationRules.addRule(value.elementName, value.validators, value.errorMessage, value.params);
        }
        else {
            //  alert("value not there" + value.elementName);
        }

    });
}

ValidationRules.addRule = function (elementSelector, validators, errorMessagesArray, ParamArray) {

    var ruleObject = {};
    var messages = {};
    $.each(validators, function (index, value) {
        ruleObject[value] = ParamArray[index];
        messages[value] = errorMessagesArray[index];
    });

    ruleObject["messages"] = messages;

    //$(elementSelector).promise().done(function () {
    //    $(this).rules('add', ruleObject);

    //    });

    $(elementSelector).each(function (index) {
        $(this).rules('add', ruleObject);
    });


};

ValidationRules.removeRule = function (elementSelector, validationName) {
    $(elementSelector).promise().done(function () {
        $(this).rules('remove', validationName);
        return true;
    });
};

//ValidationRules
//1) Rules -- it add the rules need to be applied for each html element
//2)addRules
//3) addRule
// 4) removeRule